﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace FUSE
{
    public class Map
    {
        //grid to contain all galaxy components and current position of the ship
        public Hashtable galaxyComponentsTable;    //isn't this supposed to be a hashtable
        //the gravitational forces of the planets
        public GenericForce[,] galaxyForces;

        private Texture2D backgroundTex;

        private int xSize;
        private int ySize;

        public Map()
        {
            this.xSize = 1;
            this.ySize = 1;

            galaxyComponentsTable = new Hashtable();
            galaxyForces = new GenericForce[xSize, ySize];
        }

        public Map(int gotXsize, int gotYsize)
        {
            this.xSize = gotXsize;
            this.ySize = gotYsize;

            galaxyComponentsTable = new Hashtable();
            galaxyForces = new GenericForce[xSize,ySize];
        }

        public Map(Texture2D backgroundTexture)
        {
            this.backgroundTex = backgroundTexture;
            this.xSize = backgroundTexture.Width;
            this.ySize = backgroundTexture.Height;

            galaxyComponentsTable = new Hashtable();
            galaxyForces = new GenericForce[xSize, ySize];
        }

        public int getXSize()
        {
            return xSize;
        }

        public int getYSize()
        {
            return ySize;
        }

        public override string ToString()
        {
            String output = String.Empty;
            output += "Planet locations" + "\n";
            foreach (DictionaryEntry item in galaxyComponentsTable)
            {
                output += "[" + ((GalaxyComponent)item.Value).RenderPosition.X + "," + 
                    ((GalaxyComponent)item.Value).RenderPosition.Y + "] ";
            }
            output += "\nForces\n";
            foreach (GenericForce force in galaxyForces)
            {
                output += "[" + force.Force.X + force.Force.Y + "] ";
            }
            
            output += "\nEnd map\n";

            return output;
        }

        public Texture2D BackgroundTexture
        {
            get { return backgroundTex; }
            set { backgroundTex = value; }
        }

        public void Draw(SpriteBatch spriteBatch)
        {
            spriteBatch.Draw(backgroundTex, Vector2.Zero, Color.White);

            foreach (DictionaryEntry item in galaxyComponentsTable)
            {
                ((GalaxyComponent)item.Value).Draw(spriteBatch);
            }
        }
    }
}
